using System.ComponentModel.DataAnnotations;
using MediatR;
using SmartTracking.ErrorCode;

namespace BaseData.WriteApi.Appcontext.Command.EweHistoryRecord_Files
{
    /// <summary>
    /// 创建种母历史记录命令
    /// </summary>
    public class CreateEweHistoryRecordCommand : IRequest<ApiResult<bool>>
    {
        /// <summary>
        /// 种母耳号
        /// </summary>
        [Required]
        public int EweId { get; set; }

        /// <summary>
        /// 配种日期
        /// </summary>
        [Required]
        public DateTime MatingDate { get; set; }

        /// <summary>
        /// 种公耳号
        /// </summary>
        public int RamId { get; set; }

        /// <summary>
        /// 妊检日期
        /// </summary>
        public DateTime? PregnancyCheckDate { get; set; }

        /// <summary>
        /// 妊检结果
        /// </summary>
        public string PregnancyResult { get; set; } = string.Empty;

        /// <summary>
        /// 分娩日期
        /// </summary>
        public DateTime? DeliveryDate { get; set; }

        /// <summary>
        /// 健羔数
        /// </summary>
        public int HealthyLambCount { get; set; }

        /// <summary>
        /// 健羔总重
        /// </summary>
        public decimal HealthyLambTotalWeight { get; set; }

        /// <summary>
        /// 弱羔数
        /// </summary>
        public int WeakLambCount { get; set; }

        /// <summary>
        /// 畸形数
        /// </summary>
        public int DeformedCount { get; set; }

        /// <summary>
        /// 死胎数
        /// </summary>
        public int StillbirthCount { get; set; }

        /// <summary>
        /// 木乃伊数
        /// </summary>
        public int MummyCount { get; set; }

        /// <summary>
        /// 畸胎数
        /// </summary>
        public int AbnormalCount { get; set; }

        /// <summary>
        /// 当前胎次
        /// </summary>
        [Required]
        public int CurrentParity { get; set; }

        /// <summary>
        /// 备注
        /// </summary>
        public string Note { get; set; } = string.Empty;

        /// <summary>
        /// 验证命令参数
        /// </summary>
        /// <returns>验证结果</returns>
        public bool Validate(out string errorMessage)
        {
            errorMessage = string.Empty;

            if (EweId <= 0)
            {
                errorMessage = "种母耳号必须大于0";
                return false;
            }

            if (CurrentParity <= 0)
            {
                errorMessage = "当前胎次必须大于0";
                return false;
            }

            if (PregnancyResult.Length > 100)
            {
                errorMessage = "妊检结果长度不能超过100个字符";
                return false;
            }

            if (Note.Length > 500)
            {
                errorMessage = "备注长度不能超过500个字符";
                return false;
            }

            return true;
        }
    }
}